package com.softeem.zuoye;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

/**
 * @author xiyu
 * @version 1.0
 * @date 2025/4/8 17:05
 * @description
 */
public class T1 {
    public static void main(String[] args) {
        String sourcePath = "source.txt";
        String targetPath = "target.txt";

        try (
                RandomAccessFile sourceFile = new RandomAccessFile(sourcePath, "r");
                RandomAccessFile targetFile = new RandomAccessFile(targetPath, "rw")) {

            byte[] buffer = new byte[1024];
            int len = 0;

            while ((len = sourceFile.read(buffer)) != -1) {
                targetFile.write(buffer, 0, len);
            }

            System.out.println("文件拷贝完成");

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
